package com.sofwin.yyb.controller;

import com.sofwin.yyb.entity.Appointment;
import com.sofwin.yyb.entity.User;
import com.sofwin.yyb.service.AppointmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/order")
public class AppointmentController {

    @Autowired
    AppointmentService appointmentService;

    @RequestMapping("/fy")
    public String fuYue(Integer flag,HttpSession session){
        session.setAttribute("flag",flag);
        return "redirect:/app/uo_list.html";
    }

    /**
     * 查看待赴约、待评价、已完成的订单
     * @param session
     * @return
     */
    @RequestMapping("/fy/list")
    @ResponseBody
    public List<Appointment> appointmentsList(HttpSession session){
        User user = (User)session.getAttribute("user");
        Integer flag = (Integer)session.getAttribute("flag");
        Map<String,Object> map = new HashMap<>();
        map.put("userId",user.getId());
        map.put("status",flag);
        return appointmentService.findUListByStatus(map);
    }
    /**
     * 修改订单状态
     */
    @RequestMapping("/updateStatus")
    @ResponseBody
    public String updateStatus(Integer id,Integer status){
        Map<String,Object> map = new HashMap<>();
        map.put("aId",id);
        map.put("status",status);
        appointmentService.updateUStatus(map);
        return "ok";
    }

}
